package com.dk.config;


import com.dk.controller.RecommendController;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class JobInit {

    @Autowired
    private Scheduler scheduler;

    //初始化
    @PostConstruct
    public void initjob() throws SchedulerException {

        //定义任务调度实例与Job绑定
        JobDetail detail = JobBuilder.newJob(RecommendController.class)
                .withIdentity("job_one", "job") //设置job名和组名
                .build();

        Trigger trigger = TriggerBuilder.newTrigger()//定义任务何时执行，何时结束,触发器
                .withIdentity("trigger_one", "trigger") //设置Trigger名和组名
                .startNow()
                .withSchedule(CronScheduleBuilder.cronSchedule("0 0/2 * * * ?"))//设置调度器
                .build();

        scheduler.scheduleJob(detail, trigger);
    }

}
